From c435fc1c4ea1a61cf2c1c9adc561df143df10e97 Mon Sep 17 00:00:00 2001
From: orbea <orbea@riseup.net>
Date: Mon, 28 Dec 2020 10:19:34 -0800
Subject: [PATCH 1/5] build: Remove root check for make install.

---
 bsnes/target-bsnes/GNUmakefile | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/bsnes/target-bsnes/GNUmakefile b/bsnes/target-bsnes/GNUmakefile
index f8f9fd2b..a22f3bbc 100644
--- a/bsnes/target-bsnes/GNUmakefile
+++ b/bsnes/target-bsnes/GNUmakefile
@@ -40,8 +40,6 @@ verbose: hiro.verbose ruby.verbose nall.verbose all;
 
 install: all
 ifeq ($(platform),windows)
-else ifeq ($(shell id -un),root)
-	$(error "make install should not be run as root")
 else ifeq ($(platform),macos)
 	mkdir -p ~/Library/Application\ Support/$(name)/
 	mkdir -p ~/Library/Application\ Support/$(name)/Database/
@@ -67,8 +65,6 @@ endif
 
 uninstall:
 ifeq ($(platform),windows)
-else ifeq ($(shell id -un),root)
-	$(error "make uninstall should not be run as root")
 else ifeq ($(platform),macos)
 	rm -rf /Applications/$(name).app
 else ifneq ($(filter $(platform),linux bsd),)
-- 
2.29.2

From 9f9bdcb9a0316eca9368e860a5d4ce889d9201cb Mon Sep 17 00:00:00 2001
From: orbea <orbea@riseup.net>
Date: Mon, 28 Dec 2020 10:23:35 -0800
Subject: [PATCH 2/5] build: Support DESTDIR.

---
 bsnes/target-bsnes/GNUmakefile | 38 +++++++++++++++++-----------------
 1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/bsnes/target-bsnes/GNUmakefile b/bsnes/target-bsnes/GNUmakefile
index a22f3bbc..3d7ceaf7 100644
--- a/bsnes/target-bsnes/GNUmakefile
+++ b/bsnes/target-bsnes/GNUmakefile
@@ -47,20 +47,20 @@ else ifeq ($(platform),macos)
 	mkdir -p ~/Library/Application\ Support/$(name)/Shaders/
 	cp -R out/$(name).app /Applications/$(name).app
 else ifneq ($(filter $(platform),linux bsd),)
-	mkdir -p $(prefix)/bin/
-	mkdir -p $(prefix)/share/applications/
-	mkdir -p $(prefix)/share/icons/hicolor/256x256/apps/
-	mkdir -p $(prefix)/share/icons/hicolor/scalable/apps/
-	mkdir -p $(prefix)/share/$(name)/
-	mkdir -p $(prefix)/share/$(name)/Database/
-	mkdir -p $(prefix)/share/$(name)/Firmware/
-	mkdir -p $(prefix)/share/$(name)/Shaders/
-	cp out/$(name) $(prefix)/bin/$(name)
-	cp $(ui)/resource/$(name).desktop $(prefix)/share/applications/$(name).desktop
-	cp $(ui)/resource/$(name).png $(prefix)/share/icons/hicolor/256x256/apps/$(name).png
-	cp $(ui)/resource/$(name).svg $(prefix)/share/icons/hicolor/scalable/apps/$(name).svg
-	cp Database/* $(prefix)/share/$(name)/Database/
-	cp -r ../shaders/* $(prefix)/share/$(name)/Shaders/
+	mkdir -p $(DESTDIR)$(prefix)/bin/
+	mkdir -p $(DESTDIR)$(prefix)/share/applications/
+	mkdir -p $(DESTDIR)$(prefix)/share/icons/hicolor/256x256/apps/
+	mkdir -p $(DESTDIR)$(prefix)/share/icons/hicolor/scalable/apps/
+	mkdir -p $(DESTDIR)$(prefix)/share/$(name)/
+	mkdir -p $(DESTDIR)$(prefix)/share/$(name)/Database/
+	mkdir -p $(DESTDIR)$(prefix)/share/$(name)/Firmware/
+	mkdir -p $(DESTDIR)$(prefix)/share/$(name)/Shaders/
+	cp out/$(name) $(DESTDIR)$(prefix)/bin/$(name)
+	cp $(ui)/resource/$(name).desktop $(DESTDIR)$(prefix)/share/applications/$(name).desktop
+	cp $(ui)/resource/$(name).png $(DESTDIR)$(prefix)/share/icons/hicolor/256x256/apps/$(name).png
+	cp $(ui)/resource/$(name).svg $(DESTDIR)$(prefix)/share/icons/hicolor/scalable/apps/$(name).svg
+	cp Database/* $(DESTDIR)$(prefix)/share/$(name)/Database/
+	cp -r ../shaders/* $(DESTDIR)$(prefix)/share/$(name)/Shaders/
 endif
 
 uninstall:
@@ -68,9 +68,9 @@ ifeq ($(platform),windows)
 else ifeq ($(platform),macos)
 	rm -rf /Applications/$(name).app
 else ifneq ($(filter $(platform),linux bsd),)
-	rm -f $(prefix)/bin/$(name)
-	rm -f $(prefix)/share/applications/$(name).desktop
-	rm -f $(prefix)/share/icons/hicolor/256x256/apps/$(name).png
-	rm -f $(prefix)/share/icons/hicolor/scalable/apps/$(name).svg
-	rm -rf $(prefix)/share/$(name)
+	rm -f $(DESTDIR)$(prefix)/bin/$(name)
+	rm -f $(DESTDIR)$(prefix)/share/applications/$(name).desktop
+	rm -f $(DESTDIR)$(prefix)/share/icons/hicolor/256x256/apps/$(name).png
+	rm -f $(DESTDIR)$(prefix)/share/icons/hicolor/scalable/apps/$(name).svg
+	rm -rf $(DESTDIR)$(prefix)/share/$(name)
 endif
-- 
2.29.2

From 8965225ba1a501960ab9eacd2111ea90ce69913b Mon Sep 17 00:00:00 2001
From: orbea <orbea@riseup.net>
Date: Mon, 28 Dec 2020 10:35:47 -0800
Subject: [PATCH 3/5] build: Follow FHS default paths.

---
 bsnes/target-bsnes/GNUmakefile | 37 +++++++++++++++++-----------------
 nall/GNUmakefile               |  5 ++++-
 2 files changed, 22 insertions(+), 20 deletions(-)

diff --git a/bsnes/target-bsnes/GNUmakefile b/bsnes/target-bsnes/GNUmakefile
index 3d7ceaf7..1a413a22 100644
--- a/bsnes/target-bsnes/GNUmakefile
+++ b/bsnes/target-bsnes/GNUmakefile
@@ -47,20 +47,19 @@ else ifeq ($(platform),macos)
 	mkdir -p ~/Library/Application\ Support/$(name)/Shaders/
 	cp -R out/$(name).app /Applications/$(name).app
 else ifneq ($(filter $(platform),linux bsd),)
-	mkdir -p $(DESTDIR)$(prefix)/bin/
-	mkdir -p $(DESTDIR)$(prefix)/share/applications/
-	mkdir -p $(DESTDIR)$(prefix)/share/icons/hicolor/256x256/apps/
-	mkdir -p $(DESTDIR)$(prefix)/share/icons/hicolor/scalable/apps/
-	mkdir -p $(DESTDIR)$(prefix)/share/$(name)/
-	mkdir -p $(DESTDIR)$(prefix)/share/$(name)/Database/
-	mkdir -p $(DESTDIR)$(prefix)/share/$(name)/Firmware/
-	mkdir -p $(DESTDIR)$(prefix)/share/$(name)/Shaders/
-	cp out/$(name) $(DESTDIR)$(prefix)/bin/$(name)
-	cp $(ui)/resource/$(name).desktop $(DESTDIR)$(prefix)/share/applications/$(name).desktop
-	cp $(ui)/resource/$(name).png $(DESTDIR)$(prefix)/share/icons/hicolor/256x256/apps/$(name).png
-	cp $(ui)/resource/$(name).svg $(DESTDIR)$(prefix)/share/icons/hicolor/scalable/apps/$(name).svg
-	cp Database/* $(DESTDIR)$(prefix)/share/$(name)/Database/
-	cp -r ../shaders/* $(DESTDIR)$(prefix)/share/$(name)/Shaders/
+	mkdir -p $(DESTDIR)$(bindir)
+	mkdir -p $(DESTDIR)$(datarootdir)/applications
+	mkdir -p $(DESTDIR)$(datarootdir)/icons/hicolor/256x256/apps
+	mkdir -p $(DESTDIR)$(datarootdir)/icons/hicolor/scalable/apps
+	mkdir -p $(DESTDIR)$(datadir)/$(name)/Database
+	mkdir -p $(DESTDIR)$(datadir)/$(name)/Firmware
+	mkdir -p $(DESTDIR)$(datadir)/$(name)/Shaders
+	cp out/$(name) $(DESTDIR)$(bindir)/$(name)
+	cp $(ui)/resource/$(name).desktop $(DESTDIR)$(datarootdir)/applications/$(name).desktop
+	cp $(ui)/resource/$(name).png $(DESTDIR)$(datarootdir)/icons/hicolor/256x256/apps/$(name).png
+	cp $(ui)/resource/$(name).svg $(DESTDIR)$(datarootdir)/icons/hicolor/scalable/apps/$(name).svg
+	cp Database/* $(DESTDIR)$(datadir)/$(name)/Database/
+	cp -r ../shaders/* $(DESTDIR)$(datadir)/$(name)/Shaders/
 endif
 
 uninstall:
@@ -68,9 +67,9 @@ ifeq ($(platform),windows)
 else ifeq ($(platform),macos)
 	rm -rf /Applications/$(name).app
 else ifneq ($(filter $(platform),linux bsd),)
-	rm -f $(DESTDIR)$(prefix)/bin/$(name)
-	rm -f $(DESTDIR)$(prefix)/share/applications/$(name).desktop
-	rm -f $(DESTDIR)$(prefix)/share/icons/hicolor/256x256/apps/$(name).png
-	rm -f $(DESTDIR)$(prefix)/share/icons/hicolor/scalable/apps/$(name).svg
-	rm -rf $(DESTDIR)$(prefix)/share/$(name)
+	rm -f $(DESTDIR)$(bindir)/$(name)
+	rm -f $(DESTDIR)$(datarootdir)/applications/$(name).desktop
+	rm -f $(DESTDIR)$(datarootdir)/icons/hicolor/256x256/apps/$(name).png
+	rm -f $(DESTDIR)$(datarootdir)/icons/hicolor/scalable/apps/$(name).svg
+	rm -rf $(DESTDIR)$(datadir)/$(name)
 endif
diff --git a/nall/GNUmakefile b/nall/GNUmakefile
index 0489910e..2a97fe0d 100755
--- a/nall/GNUmakefile
+++ b/nall/GNUmakefile
@@ -246,5 +246,8 @@ strne = $(if $(filter-out xx,x$(subst $1,,$2)$(subst $2,,$1)x),1,)
 ifeq ($(platform),windows)
   prefix := $(subst $([space]),\$([space]),$(strip $(call strtr,$(LOCALAPPDATA),\,/)))
 else
-  prefix := $(HOME)/.local
+  prefix ?= /usr/local
+  bindir ?= $(prefix)/bin
+  datarootdir ?= $(prefix)/share
+  datadir ?= $(datarootdir)
 endif
-- 
2.29.2

From 30b281c65de6a08132fa7ee956495747f4725097 Mon Sep 17 00:00:00 2001
From: orbea <orbea@riseup.net>
Date: Mon, 28 Dec 2020 10:57:28 -0800
Subject: [PATCH 4/5] nall: Use the value of datadir to find the assets dir.

---
 nall/GNUmakefile | 1 +
 nall/path.hpp    | 2 ++
 2 files changed, 3 insertions(+)

diff --git a/nall/GNUmakefile b/nall/GNUmakefile
index 2a97fe0d..1587a427 100755
--- a/nall/GNUmakefile
+++ b/nall/GNUmakefile
@@ -250,4 +250,5 @@ else
   bindir ?= $(prefix)/bin
   datarootdir ?= $(prefix)/share
   datadir ?= $(datarootdir)
+  flags += -DDATADIR=\"$(datadir)\"
 endif
diff --git a/nall/path.hpp b/nall/path.hpp
index 3353817b..a9f0b496 100644
--- a/nall/path.hpp
+++ b/nall/path.hpp
@@ -137,6 +137,8 @@ inline auto sharedData() -> string {
   result.transform("\\", "/");
   #elif defined(PLATFORM_MACOS)
   string result = "/Library/Application Support/";
+  #elif defined(DATADIR)
+  string result = DATADIR;
   #else
   string result = "/usr/share/";
   #endif
-- 
2.29.2

From 45328b6732e37e06596732950563178d4b5fde5b Mon Sep 17 00:00:00 2001
From: orbea <orbea@riseup.net>
Date: Wed, 30 Dec 2020 14:02:38 -0800
Subject: [PATCH 5/5] build: Allow out of tree builds.

---
 bsnes/GNUmakefile              | 22 ++++++++++---------
 bsnes/gb/GNUmakefile           | 40 +++++++++++++++++-----------------
 bsnes/processor/GNUmakefile    | 14 ++++++------
 bsnes/sfc/GNUmakefile          | 26 +++++++++++-----------
 bsnes/target-bsnes/GNUmakefile |  8 +++----
 hiro/GNUmakefile               |  4 ++--
 nall/GNUmakefile               | 10 +++++++++
 ruby/GNUmakefile               |  2 +-
 8 files changed, 69 insertions(+), 57 deletions(-)

diff --git a/bsnes/GNUmakefile b/bsnes/GNUmakefile
index 9450f39c..8a320cdf 100644
--- a/bsnes/GNUmakefile
+++ b/bsnes/GNUmakefile
@@ -1,9 +1,11 @@
+srcdir := $(abspath $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST))))))
+
 target := bsnes
 binary := application
 build := performance
 openmp := true
 local := true
-flags += -I. -I..
+flags += -I$(srcdir)/. -I$(srcdir)/..
 
 # in order for this to work, obj/lzma.o must be omitted or bsnes will hang on startup.
 # further, only the X-Video driver works reliably. OpenGL 3.2, OpenGL 2.0, and XShm crash bsnes.
@@ -17,7 +19,7 @@ ifeq ($(local),true)
   flags += -march=native
 endif
 
-nall.path := ../nall
+nall.path := $(srcdir)/../nall
 include $(nall.path)/GNUmakefile
 
 ifeq ($(platform),windows)
@@ -46,16 +48,16 @@ endif
 
 objects := libco emulator filter lzma
 
-obj/libco.o: ../libco/libco.c
-obj/emulator.o: emulator/emulator.cpp
-obj/filter.o: filter/filter.cpp
-obj/lzma.o: lzma/lzma.cpp
+obj/libco.o: $(srcdir)/../libco/libco.c maketree
+obj/emulator.o: $(srcdir)/emulator/emulator.cpp maketree
+obj/filter.o: $(srcdir)/filter/filter.cpp maketree
+obj/lzma.o: $(srcdir)/lzma/lzma.cpp maketree
 
-include sfc/GNUmakefile
-include gb/GNUmakefile
-include processor/GNUmakefile
+include $(srcdir)/sfc/GNUmakefile
+include $(srcdir)/gb/GNUmakefile
+include $(srcdir)/processor/GNUmakefile
 
-ui := target-$(target)
+ui := $(srcdir)/target-$(target)
 include $(ui)/GNUmakefile
 -include obj/*.d
 
diff --git a/bsnes/gb/GNUmakefile b/bsnes/gb/GNUmakefile
index e88ac418..b3ee9e93 100644
--- a/bsnes/gb/GNUmakefile
+++ b/bsnes/gb/GNUmakefile
@@ -1,29 +1,29 @@
-include gb/version.mk
+include $(srcdir)/gb/version.mk
 export VERSION
 
 flags += -DGB_INTERNAL -DGB_DISABLE_DEBUGGER -DGB_DISABLE_CHEATS -D_GNU_SOURCE -DGB_VERSION=\"$(VERSION)\" -Wno-multichar
-options += -I../sameboy
+options += -I$(srcdir)/../sameboy
 
 objects += gb-apu gb-camera gb-rumble gb-display gb-gb gb-joypad gb-mbc
 objects += gb-memory gb-printer gb-random gb-rewind gb-save_state gb-sgb
 objects += gb-sm83_cpu gb-symbol_hash gb-timing
 #objects+= gb-debugger gb-sm83_disassembler
 
-obj/gb-apu.o:               gb/Core/apu.c
-obj/gb-camera.o:            gb/Core/camera.c
-obj/gb-debugger.o:          gb/Core/debugger.c
-obj/gb-rumble.o:            gb/Core/rumble.c
-obj/gb-display.o:           gb/Core/display.c
-obj/gb-gb.o:                gb/Core/gb.c
-obj/gb-joypad.o:            gb/Core/joypad.c
-obj/gb-mbc.o:               gb/Core/mbc.c
-obj/gb-memory.o:            gb/Core/memory.c
-obj/gb-printer.o:           gb/Core/printer.c
-obj/gb-random.o:            gb/Core/random.c
-obj/gb-rewind.o:            gb/Core/rewind.c
-obj/gb-save_state.o:        gb/Core/save_state.c
-obj/gb-sgb.o:               gb/Core/sgb.c
-obj/gb-sm83_cpu.o:          gb/Core/sm83_cpu.c
-obj/gb-sm83_disassembler.o: gb/Core/sm83_disassembler.c
-obj/gb-symbol_hash.o:       gb/Core/symbol_hash.c
-obj/gb-timing.o:            gb/Core/timing.c
+obj/gb-apu.o:               $(srcdir)/gb/Core/apu.c
+obj/gb-camera.o:            $(srcdir)/gb/Core/camera.c
+obj/gb-debugger.o:          $(srcdir)/gb/Core/debugger.c
+obj/gb-rumble.o:            $(srcdir)/gb/Core/rumble.c
+obj/gb-display.o:           $(srcdir)/gb/Core/display.c
+obj/gb-gb.o:                $(srcdir)/gb/Core/gb.c
+obj/gb-joypad.o:            $(srcdir)/gb/Core/joypad.c
+obj/gb-mbc.o:               $(srcdir)/gb/Core/mbc.c
+obj/gb-memory.o:            $(srcdir)/gb/Core/memory.c
+obj/gb-printer.o:           $(srcdir)/gb/Core/printer.c
+obj/gb-random.o:            $(srcdir)/gb/Core/random.c
+obj/gb-rewind.o:            $(srcdir)/gb/Core/rewind.c
+obj/gb-save_state.o:        $(srcdir)/gb/Core/save_state.c
+obj/gb-sgb.o:               $(srcdir)/gb/Core/sgb.c
+obj/gb-sm83_cpu.o:          $(srcdir)/gb/Core/sm83_cpu.c
+obj/gb-sm83_disassembler.o: $(srcdir)/gb/Core/sm83_disassembler.c
+obj/gb-symbol_hash.o:       $(srcdir)/gb/Core/symbol_hash.c
+obj/gb-timing.o:            $(srcdir)/gb/Core/timing.c
diff --git a/bsnes/processor/GNUmakefile b/bsnes/processor/GNUmakefile
index e8928ebf..5dda56ca 100644
--- a/bsnes/processor/GNUmakefile
+++ b/bsnes/processor/GNUmakefile
@@ -8,10 +8,10 @@ objects += $(if $(findstring spc700,$(processors)),processor-spc700)
 objects += $(if $(findstring upd96050,$(processors)),processor-upd96050)
 objects += $(if $(findstring wdc65816,$(processors)),processor-wdc65816)
 
-obj/processor-arm7tdmi.o: processor/arm7tdmi/arm7tdmi.cpp
-obj/processor-gsu.o:      processor/gsu/gsu.cpp
-obj/processor-hg51b.o:    processor/hg51b/hg51b.cpp
-obj/processor-sm83.o:     processor/sm83/sm83.cpp
-obj/processor-spc700.o:   processor/spc700/spc700.cpp
-obj/processor-upd96050.o: processor/upd96050/upd96050.cpp
-obj/processor-wdc65816.o: processor/wdc65816/wdc65816.cpp
+obj/processor-arm7tdmi.o: $(srcdir)/processor/arm7tdmi/arm7tdmi.cpp
+obj/processor-gsu.o:      $(srcdir)/processor/gsu/gsu.cpp
+obj/processor-hg51b.o:    $(srcdir)/processor/hg51b/hg51b.cpp
+obj/processor-sm83.o:     $(srcdir)/processor/sm83/sm83.cpp
+obj/processor-spc700.o:   $(srcdir)/processor/spc700/spc700.cpp
+obj/processor-upd96050.o: $(srcdir)/processor/upd96050/upd96050.cpp
+obj/processor-wdc65816.o: $(srcdir)/processor/wdc65816/wdc65816.cpp
diff --git a/bsnes/sfc/GNUmakefile b/bsnes/sfc/GNUmakefile
index 3bbd7483..1eedfae2 100644
--- a/bsnes/sfc/GNUmakefile
+++ b/bsnes/sfc/GNUmakefile
@@ -5,18 +5,18 @@ objects += sfc-cartridge sfc-memory
 objects += sfc-cpu sfc-smp sfc-dsp sfc-ppu sfc-ppu-fast
 objects += sfc-expansion sfc-coprocessor sfc-slot
 
-obj/sfc-interface.o:   sfc/interface/interface.cpp
-obj/sfc-system.o:      sfc/system/system.cpp
-obj/sfc-controller.o:  sfc/controller/controller.cpp
-obj/sfc-cartridge.o:   sfc/cartridge/cartridge.cpp
-obj/sfc-memory.o:      sfc/memory/memory.cpp
+obj/sfc-interface.o:   $(srcdir)/sfc/interface/interface.cpp maketree
+obj/sfc-system.o:      $(srcdir)/sfc/system/system.cpp maketree
+obj/sfc-controller.o:  $(srcdir)/sfc/controller/controller.cpp maketree
+obj/sfc-cartridge.o:   $(srcdir)/sfc/cartridge/cartridge.cpp maketree
+obj/sfc-memory.o:      $(srcdir)/sfc/memory/memory.cpp maketree
 
-obj/sfc-cpu.o:         sfc/cpu/cpu.cpp
-obj/sfc-smp.o:         sfc/smp/smp.cpp
-obj/sfc-dsp.o:         sfc/dsp/dsp.cpp
-obj/sfc-ppu.o:         sfc/ppu/ppu.cpp
-obj/sfc-ppu-fast.o:    sfc/ppu-fast/ppu.cpp
+obj/sfc-cpu.o:         $(srcdir)/sfc/cpu/cpu.cpp maketree
+obj/sfc-smp.o:         $(srcdir)/sfc/smp/smp.cpp maketree
+obj/sfc-dsp.o:         $(srcdir)/sfc/dsp/dsp.cpp maketree
+obj/sfc-ppu.o:         $(srcdir)/sfc/ppu/ppu.cpp maketree
+obj/sfc-ppu-fast.o:    $(srcdir)/sfc/ppu-fast/ppu.cpp maketree
 
-obj/sfc-expansion.o:   sfc/expansion/expansion.cpp
-obj/sfc-coprocessor.o: sfc/coprocessor/coprocessor.cpp
-obj/sfc-slot.o:        sfc/slot/slot.cpp
+obj/sfc-expansion.o:   $(srcdir)/sfc/expansion/expansion.cpp maketree
+obj/sfc-coprocessor.o: $(srcdir)/sfc/coprocessor/coprocessor.cpp maketree
+obj/sfc-slot.o:        $(srcdir)/sfc/slot/slot.cpp maketree
diff --git a/bsnes/target-bsnes/GNUmakefile b/bsnes/target-bsnes/GNUmakefile
index 1a413a22..44af4a4d 100644
--- a/bsnes/target-bsnes/GNUmakefile
+++ b/bsnes/target-bsnes/GNUmakefile
@@ -1,10 +1,10 @@
 name := bsnes
 
-hiro.path := ../hiro
+hiro.path := $(srcdir)/../hiro
 hiro.resource := $(ui)/resource/bsnes.rc
 include $(hiro.path)/GNUmakefile
 
-ruby.path := ../ruby
+ruby.path := $(srcdir)/../ruby
 include $(ruby.path)/GNUmakefile
 
 objects += ui-bsnes ui-program ui-input ui-presentation
@@ -58,8 +58,8 @@ else ifneq ($(filter $(platform),linux bsd),)
 	cp $(ui)/resource/$(name).desktop $(DESTDIR)$(datarootdir)/applications/$(name).desktop
 	cp $(ui)/resource/$(name).png $(DESTDIR)$(datarootdir)/icons/hicolor/256x256/apps/$(name).png
 	cp $(ui)/resource/$(name).svg $(DESTDIR)$(datarootdir)/icons/hicolor/scalable/apps/$(name).svg
-	cp Database/* $(DESTDIR)$(datadir)/$(name)/Database/
-	cp -r ../shaders/* $(DESTDIR)$(datadir)/$(name)/Shaders/
+	cp $(srcdir)/Database/* $(DESTDIR)$(datadir)/$(name)/Database/
+	cp -r $(srcdir)/../shaders/* $(DESTDIR)$(datadir)/$(name)/Shaders/
 endif
 
 uninstall:
diff --git a/hiro/GNUmakefile b/hiro/GNUmakefile
index 94736db5..4d8d4c7f 100755
--- a/hiro/GNUmakefile
+++ b/hiro/GNUmakefile
@@ -78,13 +78,13 @@ hiro.objects := \
   $(object.path)/hiro-$(hiro).o \
   $(if $(filter windows,$(hiro)),$(object.path)/hiro-resource.o)
 
-$(object.path)/hiro-$(hiro).o: $(hiro.path)/hiro.cpp
+$(object.path)/hiro-$(hiro).o: $(hiro.path)/hiro.cpp maketree
 	$(if $(filter qt%,$(hiro)),$(info Compiling $(hiro.path)/qt/qt.moc ...))
 	$(if $(filter qt%,$(hiro)),@$(moc) -i -o $(hiro.path)/qt/qt.moc $(hiro.path)/qt/qt.hpp)
 	$(info Compiling $(subst ../,,$<) ...)
 	@$(compiler) $(hiro.flags) $(flags) $(flags.deps) -c $< -o $@
 
-$(object.path)/hiro-resource.o: $(hiro.resource)
+$(object.path)/hiro-resource.o: $(hiro.resource) maketree
 	$(info Compiling $(subst ../,,$<) ...)
 	@$(windres) $< $@
 
diff --git a/nall/GNUmakefile b/nall/GNUmakefile
index 1587a427..f9becd52 100755
--- a/nall/GNUmakefile
+++ b/nall/GNUmakefile
@@ -162,6 +162,16 @@ endif
 # rules
 default: all;
 
+maketree: $(object.path)/.tag out/.tag
+
+$(object.path)/.tag:
+	@mkdir -p obj
+	@touch $@
+
+out/.tag:
+	@mkdir -p out
+	@touch $@
+
 nall.verbose:
 	$(info Compiler Flags:)
 	$(foreach n,$(sort $(call unique,$(flags))),$(if $(filter-out -I%,$n),$(info $([space]) $n)))
diff --git a/ruby/GNUmakefile b/ruby/GNUmakefile
index 289bc530..0b79295f 100755
--- a/ruby/GNUmakefile
+++ b/ruby/GNUmakefile
@@ -91,7 +91,7 @@ endif
 
 ruby.objects := $(object.path)/ruby.o
 
-$(object.path)/ruby.o: $(ruby.path)/ruby.cpp $(call rwildcard,$(ruby.path))
+$(object.path)/ruby.o: $(ruby.path)/ruby.cpp $(call rwildcard,$(ruby.path)) maketree
 	$(info Compiling $< ...)
 	@$(compiler) $(ruby.flags) $(flags) $(flags.deps) -c $< -o $@
 
-- 
2.29.2
